home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / rhythmbox / plugins / lyrics / LyricsParse.py < prev    next >
Encoding:
Python Source  |  2009-04-07  |  2.5 KB  |  84 lines

  1. # -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
  2. #
  3. # Copyright (C) 2007 James Livingston
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # any later version.
  9. #
  10. # The Rhythmbox authors hereby grant permission for non-GPL compatible
  11. # GStreamer plugins to be used and distributed together with GStreamer
  12. # and Rhythmbox. This permission is above and beyond the permissions granted
  13. # by the GPL license by which Rhythmbox is covered. If you modify this code
  14. # you may extend this exception to your version of the code, but you are not
  15. # obligated to do so. If you do not wish to do so, delete this exception
  16. # statement from your version.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. # GNU General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU General Public License
  24. # along with this program; if not, write to the Free Software
  25. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
  26.  
  27.  
  28. import urllib
  29. import re
  30. import gobject
  31. import gconf
  32. import rb
  33.  
  34. from LyrcParser import LyrcParser
  35. from AstrawebParser import AstrawebParser
  36. from LeoslyricsParser import LeoslyricsParser
  37. from LyricWikiParser import LyricWikiParser
  38. from WinampcnParser import WinampcnParser
  39.  
  40.  
  41. engines_map = {
  42.     'lyrc.com.ar': LyrcParser,
  43.     'astraweb.com': AstrawebParser,
  44.     'leoslyrics.com': LeoslyricsParser,
  45.     'lyricwiki.org': LyricWikiParser,
  46.     'winampcn.com': WinampcnParser
  47. }
  48.  
  49.  
  50. class Parser (object):
  51.     def __init__(self, gconf_keys, artist, title):
  52.         self.title = title
  53.         self.artist = artist
  54.  
  55.         try:
  56.             self.engines = gconf.client_get_default().get_list(gconf_keys['engines'], gconf.VALUE_STRING)
  57.             if self.engines is None:
  58.                 self.engines = []
  59.         except gobject.GError, e:
  60.             print e
  61.             self.engines = []
  62.  
  63.     def searcher(self, plexer, callback, *data):
  64.         for e in self.engines:
  65.             plexer.clear()
  66.             if e in engines_map:
  67.                 parser = engines_map[e] (self.artist, self.title)
  68.                 print "searching " + e + " for lyrics"
  69.  
  70.                 parser.search(plexer.send())
  71.                 yield None
  72.  
  73.                 _, (lyrics,) = plexer.receive()
  74.                 if lyrics is not None:
  75.                     callback (lyrics, *data)
  76.                     return
  77.  
  78.         callback (None, *data)
  79.  
  80.     def get_lyrics(self, callback, *data):
  81.         rb.Coroutine (self.searcher, callback, *data).begin ()
  82.  
  83.  
  84.